<template>
  <dt-modal-edit
    ref="modal"
    title="确认凭证上传"
    :label-width="140"
    :width="500"
    @ok="onOk"
    :loading="loading"></dt-modal-edit>
</template>

<script>
  import Opt from '../opt/ConfirmOpt.js'
  import informationMgr from '@/biz/commission/information.js'
  import settlementMgr from '@/biz/commission/settlement.js'

  export default {
    data() {
      return {
        info: {
          commissionId: '',
          confirmDate: '',
          voucherAttachType: '',
          voucherConfirmAmount: 0,
          voucherAttach: null,
          delayTime: 'ONE',
          voucherRemark: null
        },
        loading: false
      }
    },
    methods: {
      onOk() {
        if (this.info.voucherAttachType == '6' || this.info.voucherAttachType == '7') {
          this.info.voucherAttach = null
        }
        settlementMgr.editSettlement(this.info).then(() => {
          this.$Message.success('确认成功')
          this.$emit('success')
          this.hide()
        })
      },
      // 获取确认凭证数据反显
      getVoucher() {
        informationMgr.getVoucher(this.info.commissionId).then((res) => {
          this.info.confirmDate = res.confirmDate || ''
          this.info.voucherAttachType = res.voucherAttachType || ''
          this.info.voucherRemark = res.voucherRemark
          this.info.delayTime = res.delayTime ?? 'ONE'
          if (res.voucherConfirmAmount) this.info.voucherConfirmAmount = Number(res.voucherConfirmAmount)
          this.info.voucherAttach = res.voucherAttach && res.voucherAttach.length ? res.voucherAttach : null
          this.$refs.modal.show(new Opt(this.info))
        })
      },
      show(info) {
        this.info.commissionId = info.commissionId
        this.info.voucherConfirmAmount = Number(info.preCommissionAmount)
        this.info.voucherRemark = info.voucherRemark
        this.info.delayTime = info.delayTime ?? 'ONE'
        this.getVoucher()
        this.$refs.modal.show(new Opt(this.info))
      },
      hide() {
        this.$refs.modal.hide()
      }
    }
  }
</script>

<style lang="scss" scoped></style>
